package cn.efunbox.afw.web.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * WebUtil 描述 web相关工具类
 *
 * @author tomas
 * @create 2017/6/19
 **/
public class WebUtil {
    /**
     *
     * 功能： <br/>
     *
     * @author xtwin <br/>
     * @version 2015年12月9日 下午3:27:54 <br/>
     */
    public static String resolveHost(HttpServletRequest request) throws Exception {
        String host = request.getHeader("x-forwarded-for");
        if ((host == null) || (host.length() == 0) || ("unknown".equalsIgnoreCase(host))) {
            host = request.getHeader("Proxy-Client-IP");
        }

        if ((host == null) || (host.length() == 0) || ("unknown".equalsIgnoreCase(host))) {
            host = request.getHeader("WL-Proxy-Client-IP");
        }

        if ((host == null) || (host.length() == 0) || ("unknown".equalsIgnoreCase(host))) {
            host = request.getRemoteAddr();
        }

        return host;
    }
}
